<!--党员组织关系转入教育表单-->
<template>
  <div class="form">
    <yd-cell-group>
      <yd-cell-item>
        <span slot="left" class="label required">入学时间</span>
        <xf-date-picker
          :valid="[{required: true, msg: '请选择入学时间'}]"
          v-model="form.aae030"
          ref="aae030"
          placeholder="请选择入学时间"
          :endDate="new Date()"
          slot="right"></xf-date-picker>
      </yd-cell-item>
      <yd-cell-item>
        <span slot="left" class="label required">毕业时间</span>
        <xf-date-picker
          :valid="[{required: true, msg: '请选择毕业时间'}]"
          v-model="form.aac046"
          ref="aac046"
          placeholder="请选择毕业时间"
          slot="right"></xf-date-picker>
      </yd-cell-item>
      <yd-cell-item>
        <span slot="left" class="label required">毕业院校</span>
        <xf-input
          slot="right"
          :valid="[{required: true, msg: '请输入毕业院校'}]"
          v-model="form.aac045"
          ref="aac045"
          placeholder="请输入毕业院校"></xf-input>
      </yd-cell-item>
      <yd-cell-item>
        <span slot="left" class="label required">专业</span>
        <xf-picker
          slot="right"
          :valid="[{required: true, msg: '请选择所学专业'}]"
          v-model="form.acc01g"
          ref="acc01g"
          :list="profession"
          placeholder="请选择所学专业"></xf-picker>
      </yd-cell-item>
      <yd-cell-item>
        <span slot="left" class="label">学历</span>
        <xf-picker
          slot="right"
          :valid="[{required: true, msg: '请选择学历'}]"
          v-model="form.atc011"
          ref="atc011"
          :list="edu"
          placeholder="请选择学历"></xf-picker>
      </yd-cell-item>
    </yd-cell-group>
    <div class="right-bottom">
      <mt-button type="default" size="small" @click="cancel">取消</mt-button>
      <mt-button type="primary" size="small" @click="onSubmit">保存</mt-button>
    </div>
  </div>
</template>
<script>
  import XfDatePicker from '../../../components/xf-date-picker/xf-date-picker.vue'
  import XfInput from '../../../components/xf-input/xf-input.vue'
  import XfPicker from '../../../components/xf-picker/xf-picker.vue'
  import {echo, validate} from '../../../common/js/util'
  import {dics, getDics} from '../../../common/js/dictionaries'

  export default {
    props: {
      detail: {type: null, default: () => { return {} }}
    },
    components: {
      XfPicker,
      XfInput,
      XfDatePicker},
    name: 'roll-in-form',
    data() {
      return {
        form: {
          personId: this.$route.query.id,
          aac0d0: '', // id
          aae030: '', // 入学时间
          aac046: '', // 毕业时间
          aac045: '', // 毕业院校
          acc01g: '', // 专业
          atc011: '' // 学历
        },
        profession: [],
        edu: []
      }
    },
    methods: {
      cancel() {
        this.$emit('cancel')
      },
      onSubmit() {
        validate.bind(this)(this.form).then(() => {
          this.$post('/admin/person/sapi/party/education/background/update', this.form, loading => { this.$message.loading(loading) }).then(res => {
            this.$emit('save')
          })
        })
      },
      getDics() {
        getDics(dics.profession, dics.edu).then(res => {
          this.profession = res[0]
          this.edu = res[1]
        })
      }
    },
    created() {
      this.getDics()
      echo(this.form, this.detail)
    }
  }
</script>
